<!--新增会员-->
<template>
  <section class="webview fixHeight">
    <el-scrollbar style="height:100%">
      <!--      经纪人-->
      <el-form  ref="form" :model="detail" label-width="100px" class="form">
        
       
        <el-form-item label="门店名字">
          <el-input v-model="detail.name" />
        </el-form-item>
        <el-form-item label="手机号">
          <el-input v-model="detail.phone" @input='detail.account=detail.phone'/>
        </el-form-item> 
		<el-form-item label="全景地址">
          <el-input v-model="detail.vrPath" />
        </el-form-item>
		<el-form-item label="门店地址">
          <el-input v-model="detail.address" />
        </el-form-item>
		<!-- <el-form-item label="设计团队数量">
          <el-input v-model="detail.designerNumber" />
        </el-form-item>
		<el-form-item label="施工队数量">
          <el-input v-model="detail.onstructionTeamNumber" />
        </el-form-item> -->
		<!-- <el-form-item label="门店数量">
          <el-input v-model="detail.storeNumber" />
        </el-form-item> -->
		<!-- <el-form-item label="品牌类型">
          <el-input v-model="detail.undertakeType" />
        </el-form-item> -->
		<!-- <el-form-item label="标签">
          <el-input multiple v-model="detail.tag" />
        </el-form-item> -->
		<el-form-item label="所属公司">
		  <el-select v-model="detail.enterpriseId" placeholder="请选择">
		    <el-option
		      v-for="item in list"
		      :key="item.id"
		      :label="item.name"
		      :value="item.id"
		    />
		  </el-select>
		</el-form-item>
		
		<el-form-item label="简介">
		  <el-input type="textarea" :rows="4" v-model="detail.introduction" />
		</el-form-item>
		<el-form-item  label="公司LOGO">
		  <div class="picList">
		    <div class="item" v-if="detail.headPortrait != ''" >
		      <img class="pic" :src="detail.headPortrait" alt>
		      <i class="el-icon-delete delIcon hand" @click="handlesRemoveL(item,index)" />
		    </div>
		  </div>
		  <div  class="item itemNo" v-if="detail.headPortrait==''">
		    <el-upload
			:action="Is.sevenDomain2"
		    :data="qiniuData"
		    multiple
		      name="file"
		      :show-file-list="false"
		      :before-upload="handleUpload"
		      :on-success="handlesSuccessL"
		    >
		      <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，只能上传1张，且不超过10M</div>
		      <div class="el-upload el-upload--picture-card">
		        <i slot="default" class="el-icon-plus" />
		      </div>
		    </el-upload>
		  </div>
		</el-form-item>
        <el-form-item  label="展示图片">
          <div class="picList">
            <div class="item" v-for="(l,index) in showPicturess" :key='index'>
              <img class="pic" :src="l" alt>
              <i class="el-icon-delete delIcon hand" @click="handlesRemove(item,index)" />
            </div>
          </div>
          <div  class="item itemNo">
            <el-upload
             :action="Is.sevenDomain2"
              :data="qiniuData"
              multiple
              name="file"
              :show-file-list="false"
              :before-upload="handleUpload"
              :on-success="handlesSuccess"
            >
              <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，只能上传1张，且不超过10M</div> -->
              <div class="el-upload el-upload--picture-card">
                <i slot="default" class="el-icon-plus" />
              </div>
            </el-upload>
          </div>
        </el-form-item>
		<el-form-item  label="上传视频">
		  <el-upload
		    accept="video/mp4"
			:action="Is.sevenDomain2"
		    :data="qiniuData"
		    :show-file-list="true"
			:before-upload="handleUpload"
		    :before-remove="(res)=>{detail.videoPath='';return true}"
		    :on-success="successVideo"
		  >
		    <span
		      slot="tip"
		      class="el-upload__tip"
		      style="padding-left:15px;"
		    >建议上传mp4格式视频</span>
		    <div class="avatarWrap">
		      <el-button type="success" round class="button">点击上传</el-button>
		    </div>
		  </el-upload>
		</el-form-item>
     <el-form-item>
<!--          <el-button type="primary" @click="submit">提交</el-button>-->
          <el-button @click="cancel">返回</el-button>
          <el-button @click="ok">提交</el-button>
        </el-form-item>
      </el-form>
      
     
      
    </el-scrollbar>
  </section>
</template>
<script>
  import {addMaterialsEnterpriseStore,craeteToken,updateMaterialsStore,listMaterialsEnterprise} from '@/api/api'
  export default {
    data() {
      return {
		  id:0,
       showPicturess:[],
	   list:[],
        detail: {
			 "account": "",
			  "address": "",
			  "coverPhoto": "",
			  "designerNumber": '',
			  "enterpriseId": "",
			  "headPortrait": "",
			  "introduction": "",
			  "name": "",
			  "onstructionTeamNumber": '',
			  "phone": "",
			  "showPictures": "",
			  "storeNumber": '',
			  "tag": "",
			  "undertakeType": "",
			  "videoPath": "",
			  "vrPath": ""
		},
		videoFlag:false,
		videoUploadPercent:0,
		upload_qiniu_addr:'http://qinniu.qimazf.com/',
		qiniuData: {
		        key: "aNmGG9Cs19xKonjerU5T47y4K9OfUqSAO20-3vIj",
		        token: ""
		      },
      }
    },
    created() {
      this.getQiniuToken()
	  if(this.$route.query.data){
		  var data=JSON.parse( this.$route.query.data );
		if(data.showPictures != ''){
					   this.showPicturess=data.showPictures.split(',')
		}
		      this.detail = data
		     this.id=data.id
	  }
		this.getList()
        
        
    },
    methods: {
		// 返回
		cancel() {
		  this.$router.back()
		},
		successVideo(res,file){
			
					this.detail.videoPath='';
					this.detail.videoPath=this.upload_qiniu_addr + res.key;
					this.detail.coverPhoto= this.upload_qiniu_addr + res.key+'?vframe/jpg/offset/1';
					
				
		},
		getList() {
		  const params = {
		    curPage: 1,
		    pageSize: 100,
		  }
		  listMaterialsEnterprise(params).then(data => {
			  this.list = data.data.records
			
			
		  })
		},
		handleUpload(file) {
		 const timeStamp = new Date() - 0
		var num=Math.floor(Math.random()*10000000)
		const copyFile = new File([file], `${timeStamp}_`+num);
		  this.qiniuData.key = copyFile.name;
		 },
		getQiniuToken: function() {
		     const _this = this;
		    craeteToken().then(({ data }) => {
		     console.log(data)
					_this.qiniuData.token=data
		    })
		   },
		handlesSuccess(res) {
			var that = this
		   that.showPicturess.push(that.upload_qiniu_addr + res.key)
		 
		},
		handlesRemove(item,index){
			this.showPicturess.splice(index,1)
		},
		handlesSuccessL(res) {
			var that = this
		   that.detail.headPortrait=this.upload_qiniu_addr + res.key
		 
		},
		handlesRemoveL(item,index){
			var that = this
			that.detail.headPortrait=''
		},
		ok(){
			var that=this;
			that.detail.showPictures=that.showPicturess.join(',')
			var da=that.detail
			if(this.id!=0){
				updateMaterialsStore(da).then(data => {
				  Is.tip('编辑成功')
				   this.$router.go(-1)
				})
			}else{
				addMaterialsEnterpriseStore(da).then(data => {
				  Is.tip('设置成功')
				   this.$router.go(-1)
				})
			}
			
			
		},
		back(){
			var that=this;
			this.$prompt('请输入打回理由', '提示', {
			          confirmButtonText: '确定',
			          cancelButtonText: '取消'
			        }).then(({ value }) => {
						agentUpdateStatus({
						  id: that.id,
						  status:4,
						  remark:value
						}).then(data => {
						  Is.tip('设置成功');
						   this.$router.go(-1)
						});
			        }).catch(() => {
			               
			        });
				  		 
			
		}
    }}
</script>
